--穹流涤火
local qiuliudihuo = fk.CreateSkill {
    name = "mcdh_qiuliudihuo",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

qiuliudihuo:addEffect(fk.CardUseFinished,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and data.extra_data and data.extra_data.qiuliudihuo and #data.extra_data.qiuliudihuo > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if data.extra_data and data.extra_data.qiuliudihuo then
            if table.contains(data.extra_data.qiuliudihuo,2) then
                U.askForUseVirtualCard(room,player,"iron_chain",nil,self.name,"#mcdh_qiuliudihuo_2")
            end
            if table.contains(data.extra_data.qiuliudihuo,1) then
                U.askForUseVirtualCard(room,player,"thunder__slash",nil,self.name,"#mcdh_qiuliudihuo_1",false,true,false,true)
            end
        end
    end,
})

qiuliudihuo:addEffect(fk.Damage,{
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and data.card
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if e then
            e.data[1].extra_data = e.data[1].extra_data or {}
            e.data[1].extra_data.qiuliudihuo = e.data[1].extra_data.qiuliudihuo or {}
            if data.damageType == fk.NormalDamage then
                table.insertIfNeed(e.data[1].extra_data.qiuliudihuo,1)
            else
                table.insertIfNeed(e.data[1].extra_data.qiuliudihuo,2)
            end
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_qiuliudihuo"] = "穹霆",
    [":mcdh_qiuliudihuo"] = "『穹流涤火』<br>当你使用牌结算后，若此牌造成过：属性伤害，你可以视为使用一张【铁索连环】；普通伤害，你可以视为使用一张雷【杀】。",
    ["#qiuliudihuo-use"] = "穹流涤火:视为使用一张的 %arg ",
    ["#mcdh_qiuliudihuo_2"] = "穹流涤火:你可以使用一张【铁索连环】",
    ["#mcdh_qiuliudihuo_1"] = "穹流涤火:你可以使用一张雷【杀】"
}

return qiuliudihuo